package com.jiayuge.server.mapper;

import com.jiayuge.server.common.entity.RespBean;
import com.jiayuge.server.pojo.Department;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Jiayu.Yang
 * @since 2021-11-15
 */
public interface DepartmentMapper extends BaseMapper<Department> {

    //获取所有部门
    List<Department> getAllDepartment(Integer parentId);

    //添加部门
    void addDepartment(Department department);

    //删除部门
    void deleteDep(Department department);
    /*
    CREATE DEFINER=`root`@`localhost` PROCEDURE `deleteDep`(in did int,out result int)
begin
  declare ecount int;
  declare pid int;
  declare pcount int;
  declare a int;
  select count(*) into a from t_department where id=did and isParent=false;
  if a=0 then set result=-2;
  else
  select count(*) into ecount from t_employee where departmentId=did;
  if ecount>0 then set result=-1;
  else
  select parentId into pid from t_department where id=did;
  delete from t_department where id=did and isParent=false;
  select row_count() into result;
  select count(*) into pcount from t_department where parentId=pid;
  if pcount=0 then update t_department set isParent=false where id=pid;
  end if;
  end if;
  end if;
end
     */
}
